package org.zephyr.fastboot.model;

import org.zephyr.fastboot.constant.StatusCode;

import java.io.Serial;
import java.io.Serializable;

/**
 * @Author: ZephyrGao
 * @Date: 2024/6/24 08:04
 * @Description: 接口返回的数据格式
 */


public class Result<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    private boolean success;
    private int code;
    private String message;
    private T data;

    public Result() {
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // Getters and setters
    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // Static methods for easy response creation
    public static <T> Result<T> success() {
        return new Result<>(StatusCode.SUCCESS, "Success");
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(StatusCode.SUCCESS, "Success", data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(StatusCode.SUCCESS, message, data);
    }

    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message);
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(StatusCode.INTERNAL_SERVER_ERROR, message);
    }
}


